<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('列表')" />
</head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								商户名称：<input type="text" name="name"/>
							</li>

							<li>
								商户编码：<input type="text" name="code"/>
							</li>

							<li>
								商户状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
							</select>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="merchant:mpMerchant:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-success" onclick="methodStatus()">
					<i class="fa fa-edit"></i> 批量费率
				</a>
				<a class="btn btn-success" onclick="methodSwitch()">
					<i class="fa fa-edit"></i> 批量开关
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="merchant:mpMerchant:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('merchant:mpMerchant:edit')}]];
        var removeFlag = [[${@permission.hasPermi('merchant:mpMerchant:remove')}]];
        var prefix = ctx + "merchant/merchantInfo";
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "商户信息",
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : '商户标识',
					visible: false
				},
				{
					field : 'name', 
					title : '商户名称',
					sortable: true
				},
				{
					field : 'code', 
					title : '商户编码',
					sortable: true
				},
				{
					field : 'secretKey', 
					title : '商户密钥',
					sortable: true
				},
                {
                    field : 'withdrawalPassword',
                    title : '提款密码',
                    sortable: true
                },
                {
                    field : 'googleSecret',
                    title : '谷歌校验秘钥',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return '<a onclick="QRcode(\'' + row.code + '\', \'' + value + '\')">'+ value +'</a> ';
                    }
                },
				{
					field : 'userId',
					title : '用户标识',
					sortable: true,
					visible: false
				},
				{
					field : 'userLoginName',
					title : '管理账号'
				},
				{
					field : 'contactName',
					title : '联系人名称',
					sortable: true,
					visible: false
				},
				{
					field : 'contactPhone',
					title : '联系人电话',
					sortable: true,
					visible: false
				},
				{
					field : 'contactEmail',
					title : '联系人邮箱',
					sortable: true,
					visible: false
				},
                {
                    visible: editFlag == 'hidden' ? false : true,
                    field : 'status',
                    title : '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return merchantInfo_statusTools(row);
                    }
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
						actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="payMethod(\'' + row.id + '\')"><i class="fa fa-edit"></i>支付方法</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="merchantIP(\'' + row.id + '\')"><i class="fa fa-edit"></i>IP白名单</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="#" onclick="merchantBank(\'' + row.id + '\')"><i class="fa fa-edit"></i>收款银行</a> ');
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>修改</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });

        /**
         * 商户支付方法 - 批量费率
         */
        function methodStatus() {
            var url = prefix + '/methodStatus';
            $.modal.open("批量费率", url);
        }



        /**
         * 商户支付方法 - 批量开关
         */
        function methodSwitch() {
            var url = prefix + '/methodSwitch';
            $.modal.open("批量开关", url);
        }




		/**
		 *商户信息状态显示
		 */
		function merchantInfo_statusTools(row) {
			if (row.status == 1) {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="merchantInfo_enable(\'' + row.id + '\')"></i> ';
			} else {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="merchantInfo_disable(\'' + row.id + '\')"></i> ';
			}
		}

		/**
		 * 商户信息状态-停用
		 */
		function merchantInfo_disable(merchantInfoId) {
			$.modal.confirm("确认要停用所选商户信息吗？", function () {
				$.operate.post(prefix + "/changeStatus", {"id": merchantInfoId, "status": 1})
			});
		}

		/**
		 * 商户信息状态-启动
		 */
		function merchantInfo_enable(merchantInfoId) {
			$.modal.confirm("确认要启用所选商户信息吗？", function () {
				$.operate.post(prefix + "/changeStatus", {"id": merchantInfoId, "status": 0})
			});
		}

		/**
		 * 商户支付方法
		 */
		function payMethod(mpMerchantId) {
			var url = prefix + '/payMethod/' + mpMerchantId;
			$.modal.openTab("商户-支付方法", url);
		}

        /*商户-IP白名单*/
        function merchantIP(mpMerchantId) {
            var url = prefix + '/ipList/' + mpMerchantId;
            $.modal.openTab("商户-IP白名单", url);
        }


        /*商户-收款银行*/
        function merchantBank(mpMerchantId) {
            var url = prefix + '/merchantBank/' + mpMerchantId;
            $.modal.openTab("商户-收款银行", url);
        }



        /*商户秘钥二维码*/
        function QRcode(code, value) {
            var msg = "四方系统-" + code;
            console.log(msg);
            layer.open({
                type: 2,
                title: '二维码',
                // maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area : ['200px' , '250px'],
                content: ctx + 'tool/googleCode/createQRcode?userId='+ msg +'&secret=' + value
            });
        }

    </script>
</body>
</html>